#!/usr/bin/php
<?php

if(count($argv) != 2  || in_array('-h', $argv) || in_array('--help', $argv)) {
	echo "Delete a category from SmugMug\n",
	"Usage: cat-delete categoryname\n";
	die();
}

require_once('includes/utility.php');

$category = $argv[1];

$l->heading('Deleting Category ' . $category);

$l->status('Getting Categories');
$categories = $s->categories_get();
$l->done();

foreach($categories as $cat) {
	if($cat['Name'] == $category && $cat['Type'] == 'User') {
		$l->status('Deleting category');
		try{
			$s->categories_delete("CategoryID={$cat['id']}");
			$l->done();
		} catch (Exception $e){
			$l->exception($e);
		}
		exit();
	}
}

$l->writeLine('Category Not Found');